package com.sos.widget.app.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sos.widget.R;
import com.sos.widget.view.pay_ui.PayPwdView;
import com.sos.widget.view.pay_ui.PwdInputMethodView;

/**
 * @Description
 * @Author 梁浩文
 * @Date 2023/7/7 16:02
 */
public class PayPasswordDialog {
    public interface ForgetCallBack {
        void forget();
    }

    public static final class Builder
            extends BaseDialog.Builder<PayPasswordDialog.Builder> {
        public boolean passWordType = false;
        public Bundle bundle;
        int titleTextId;
        String titleTextValue;
        int forgetTextId;
        String forgetTextValue;
        private PayPwdView psw_input;
        private PayPwdView.InputCallBack inputCallBack;
        private ForgetCallBack forgetCallBack;
        private String type = "";
        private String money = "";

        public Builder(Context context) {
            super(context);
            setContentView(R.layout.dialog_pay);
        }

        public void setPassWordType(boolean passWordType) {
            this.passWordType = passWordType;
            if (passWordType) {
                findViewById(R.id.pay_money).setVisibility(View.GONE);
                findViewById(R.id.type_tv).setVisibility(View.GONE);
            }
        }

        public void setBundle(Bundle bundle) {
            this.bundle = bundle;
        }

        public void setForgetCallBack(ForgetCallBack forgetCallBack) {
            this.forgetCallBack = forgetCallBack;
        }

        @Override
        public BaseDialog show() {
            BaseDialog show = super.show();
            initView();
            return show;
        }

        private void initView() {
            psw_input = (PayPwdView) findViewById(R.id.payPwdView);
            PwdInputMethodView inputMethodView = (PwdInputMethodView) findViewById(R.id.inputMethodView);
            psw_input.setInputMethodView(inputMethodView);
            psw_input.setInputCallBack(inputCallBack);

            ((TextView) findViewById(R.id.type_tv)).setText(type);
            ((TextView) findViewById(R.id.money_tv)).setText(money);

            findViewById(R.id.iv_close_rl).setOnClickListener(this);
            if (passWordType) {
                findViewById(R.id.pay_money).setVisibility(View.GONE);
                findViewById(R.id.type_tv).setVisibility(View.GONE);
            }
            findViewById(R.id.pay_forget).setOnClickListener(this);
            if (titleTextId != 0) {
                this.<TextView>findViewById(R.id.title).setText(titleTextId);
            }
            if (forgetTextId != 0) {
                this.<TextView>findViewById(R.id.pay_forget).setText(forgetTextId);
            }
            if (!TextUtils.isEmpty(titleTextValue)) {
                this.<TextView>findViewById(R.id.title).setText(titleTextValue);
            }
            if (!TextUtils.isEmpty(forgetTextValue)) {
                this.<TextView>findViewById(R.id.pay_forget).setText(forgetTextValue);
            }
        }

        public void setTitleText(int resId) {
            titleTextId = resId;
            if (titleTextId != 0) {
                this.<TextView>findViewById(R.id.title).setText(titleTextId);
            }

        }

        public void setForgetText(int resId) {
            forgetTextId = resId;
            if (forgetTextId != 0) {
                this.<TextView>findViewById(R.id.pay_forget).setText(forgetTextId);
            }

        }

        public void setTitleText(String value) {
            titleTextValue = value;
            if (!TextUtils.isEmpty(titleTextValue)) {
                this.<TextView>findViewById(R.id.title).setText(titleTextValue);
            }

        }

        public void setForgetText(String value) {
            forgetTextValue = value;
            if (!TextUtils.isEmpty(forgetTextValue)) {
                this.<TextView>findViewById(R.id.pay_forget).setText(forgetTextValue);
            }
        }

        @Override
        public void onClick(View v) {
            if (v.getId() == R.id.iv_close_rl) {
                dismiss();
            } else if (v.getId() == R.id.pay_forget) {
                forgetCallBack.forget();
                dismiss();
                //忘记密码
            }
        }

        /**
         * 设置输入回调
         *
         * @param inputCallBack
         */
        public void setPaySuccessCallBack(PayPwdView.InputCallBack inputCallBack) {
            this.inputCallBack = inputCallBack;
        }


        public void setType(String type) {
            this.type = type;
        }

        public void setMoney(String money) {
            this.money = money;
        }
    }

}
